﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace HotelManger2012
{    
    public partial class Form1Manager : Form
    {
        public static List<Klient> klienci = new List<Klient>();
        
        public Form1Manager()
        {
            InitializeComponent();
            DoubleBuffered = true;           
        }

        private void zamknijToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void dodajKlientaToolStripMenuItem_Click(object sender, EventArgs e)
        {
                Form2Rejestruj form = new Form2Rejestruj();
                form.Show();    
        }

        private void wyrejestrujKlientaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Form1Manager.klienci.Count == 0)
                MessageBox.Show("Nie ma zarejestrowanych gości.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
            {
                Form3Wyrejestruj form = new Form3Wyrejestruj();
                form.Show();
            }
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void informacjeOKlientachToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Form1Manager.klienci.Count == 0)
                MessageBox.Show("Nie ma zarejestrowanych gości.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
            {
                Form4Informacje form = new Form4Informacje();
                form.Show();
            }
        }
        private void zapiszListeKlientowToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StreamWriter zapis = new StreamWriter("klienci.txt");
            
            for (int i = 0; i < klienci.Count; i++)
            {
                zapis.WriteLine(klienci[i].getImie() + "," + klienci[i].getNazwisko() + "," + klienci[i].getWiek() + "," + klienci[i].getPesel() + "," + klienci[i].getNr_pokoju() + "," + klienci[i].getLiczba_dni());
            }
            zapis.Close();
        }

        private void wczytajListeKlientowToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StreamReader plik = new StreamReader("klienci.txt");
            string lista;
            string[] dane;
            while (plik.EndOfStream == false)
            {
                lista = plik.ReadLine();
                dane = lista.Split(',');
                klienci.Add(new Klient(dane[0], dane[1], int.Parse(dane[2]), int.Parse(dane[3]), int.Parse(dane[4]), int.Parse(dane[5])));
            }            
        }
        private void wolnePokojeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form6WolnePokoje form = new Form6WolnePokoje();
            form.Show();
        }

        private void zajetePokojeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form5ZajetePokoje form = new Form5ZajetePokoje();
            form.Show();
        }

        private void oProgramieToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("HotelManager2012\r\n\r\nautorzy:\r\n\r\n* Paweł Długosz\r\n* Rafał Iwko\r\n* Jakub Sobczyński");
        }

        private void rachunekKlientaToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
    }
}
